<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-07-12
 * Time: 16:21
 */
namespace app\home\controller;

use think\Controller;

class Share extends Controller {

    function createSharePng($gData,$filename){
        $im = imagecreatefrompng($filename);
        //商品描述
        //字体文件
        $font_file = "code_png/msyh.ttf";
        $font_file_bold = "code_png/msyh_bold.ttf";
        //设定字体的颜色
        $font_color_1 = ImageColorAllocate ($im, 140, 140, 140);
        $font_color_2 = ImageColorAllocate ($im, 28, 28, 28);
        $font_color_3 = ImageColorAllocate ($im, 129, 129, 129);
        $font_color_red = ImageColorAllocate ($im, 217, 45, 32);
        $theTitle = cn_row_substr($gData['title'],1,18);
        imagettftext($im, 14,0, 45, 70, $font_color_2 ,$font_file, $theTitle[1]);
        imagettftext($im, 19,0, 155, 108, $font_color_red ,$font_file, "券后价￥".$gData["price"]);
        imagettftext($im, 14,0, 126, 140, $font_color_1 ,$font_file, "市场价".$gData["original_price"].'元 限时限量');
        imagettftext($im, 19,0, 220, 690, $font_color_red ,$font_file, "领".$gData["coupon_price"].'元优惠券');

        //商品图片
        list($g_w,$g_h) = getimagesize($gData['pic']);
        $goodImg = createImageFromFile($gData['pic']);
        imagecopyresized($im, $goodImg, 0, 173, 0, 0, 430, 430, $g_w, $g_h);

        //二维码
        $qrcode_img = code_create($gData["itemid"],$gData["shoptype"]);
        list($code_w,$code_h) = getimagesize($qrcode_img);
        $codeImg = createImageFromFile($qrcode_img);
        unlink($qrcode_img);
        imagecopyresized($im, $codeImg, 15, 620, 0, 0, 170, 170, $code_w, $code_h);
        return $im;
    }

}